﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WebTranslator;
namespace TranslationClient
{
  public partial class WykonanieTlumaczenia : Form
  {
    string id;
    KlientWT Rodzic;
    CMSProtocolC cp;
    public WykonanieTlumaczenia(  CMSProtocolC cp, KlientWT par)
    {
      this.cp = cp;
      Rodzic = par;
      InitializeComponent();
      cp.Send("listatematow");
      int siz = Int32.Parse(cp.Receive().ToString());
      List<string> L = new List<string>();
      for (int i = 0; i < siz; i++) L.Add(cp.Receive());
      comboBox1.DataSource = L;
			button2.Enabled = L.Count > 0;
			button1.Enabled = false;			
    }

    private void button2_Click(object sender, EventArgs e)
    {
      textBox1.Text = "";
      id = "";
      cp.Send("pokaz " + comboBox1.SelectedValue.ToString());
      string temp = cp.Receive();
      bool t = true;
      for (int i = 0; i < temp.Length; i++)
        if (temp[i] != ' ' && t) { if (t) id += temp[i]; }
        else
        {
          if (t) t = false;
          else
            textBox1.Text += temp[i];
        }
      textBox1.Text = textBox1.Text.Replace("//", Environment.NewLine);
	  button1.Enabled = true;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        string tresc = textBox2.Text.Replace(Environment.NewLine,"//");
      cp.Send("zrobilem " + id + ' ' + tresc);
      string pkt = cp.Receive();
      Rodzic.setPoint(pkt);
      cp.Send("listatematow");
      int siz = Int32.Parse(cp.Receive().ToString());
      List<string> L = new List<string>();
      for (int i = 0; i < siz; i++) L.Add(cp.Receive());
      comboBox1.DataSource = L;
			Close();
    }
  }
}
